home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 12 / Amiga Format AFCD12 (Apr 1997, Issue 96).iso / -in_the_mag- / html_tutorial / cgi_qs.ada < prev    next >
Text File  |  1997-01-21  |  1KB  |  51 lines

  1. -- (C) M.A.Smith University of Brighton
  2. --
  3. -- Permission is granted to use this code
  4. --   provided this declaration and copyright notice remains intact.
  5. --
  6. -- 26 August 1995
  7.  
  8. PACKAGE unix_if IS
  9.   FUNCTION get_env( str:IN String ) RETURN String;
  10. END unix_if;
  11.  
  12. WITH Interfaces.C, Interfaces.C.Strings;
  13. USE  Interfaces.C, Interfaces.C.Strings;
  14. PACKAGE BODY unix_if IS
  15.  
  16. FUNCTION get_env( str:IN String ) RETURN String IS
  17.   FUNCTION getenv( str:IN Char_array ) RETURN Chars_ptr;
  18.   PRAGMA import (C, getenv, "getenv");
  19.   res : Chars_ptr;
  20. BEGIN
  21.   res := getenv( to_c( str, append_nul=>TRUE ) );
  22.   IF res = NULL_PTR THEN
  23.     RETURN "";
  24.   ELSE
  25.     RETURN value(res);
  26.   END IF;
  27. END get_env;
  28.  
  29. END unix_if;
  30.  
  31. WITH Simple_io, unix_if;
  32. USE  Simple_io, unix_if;
  33. PROCEDURE main IS
  34. BEGIN
  35.   new_line;
  36.   put( "Content-type: text/html" ); new_line(2);
  37.   put( "<" &"HTML> " ); new_line;
  38.   put( "<HEAD>" );      new_line;
  39.   put( "</HEAD>" );     new_line;
  40.   put( "<BODY>" );      new_line;
  41.   put( "<P>" );         new_line;
  42.   put( "The data sent to the form processing program " ); new_line;
  43.   put( "in the environment variable QUERY_STRING is:" ); new_line;
  44.   put( "<P>" );         new_line;
  45.   put( get_env( "QUERY_STRING" ) ); new_line;
  46.   put( "<P>" );         new_line;
  47.   put( "</BODY>  " );   new_line;
  48.   put( "<" &"/HTML>" ); new_line;
  49. END main;
  50.  
  51.